package com.infore.operation.controller;

import com.infore.operation.entity.Equip;
import com.infore.operation.entity.PositionStation;
import com.infore.operation.entity.Station;
import com.infore.operation.service.StationService;
import com.infore.operation.utils.AbstractJsonObject;
import com.infore.operation.utils.FormatUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.List;

/**
 * @author:wk
 * @date:Created in 16:16 2018\4\16 0016
 */
@RestController
public class StationController {

    @Autowired
    private StationService stationService;

    /**
     * 根据用户id查询站点
     * @param userId
     * @return
     */
    @RequestMapping("/servlet/queryStationByuserId.do")
    public AbstractJsonObject queryStationByuserId(@RequestParam(value = "userId") String userId) {
        List<Station> list = stationService.queryStationByUserId(userId);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("beanList", list);
        return FormatUtil.queryListObject(map,"获取站点数据成功");
    }

    /**
     * 根据站点获取设备
     * @param stationId
     * @return
     */
    @RequestMapping("/servlet/EquipBySId.do")
    public AbstractJsonObject  queryEquipBySId(
            @RequestParam(value="stationId") String stationId){
        List<Equip> list = stationService.queryEquipBySId(stationId);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("Equiplist", list);
        return FormatUtil.queryListObject(map,"获取设备数据成功");
    }

    /**
     * 根据人员获取所有站点
     * @param userId
     * @param pageNum
     * @param keyword
     * @return
     */
    @RequestMapping("/servlet/queryAllStationByuserId.do")
    public AbstractJsonObject queryAllStationByuserId(@RequestParam(value = "userId") String userId,
                                                      @RequestParam(value = "pageNum") Integer pageNum,
                                                      @RequestParam(value = "keyword") String keyword){
        List<PositionStation> list = stationService.queryAllStationByuserId(userId,pageNum,keyword);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("beanList", list);
        return FormatUtil.queryListObject(map,"获取所有站点成功");
    }

    /**
     * 获取附近的站点
     * @param userId
     * @param lat
     * @param lnt
     * @return
     */
    @RequestMapping("/servlet/NearStation.do")
    public AbstractJsonObject queryNearStation(@RequestParam(value = "userId") String userId,
                                   @RequestParam(value = "lat") String lat,
                                   @RequestParam(value = "lnt") String lnt){
        List<PositionStation> list = stationService.queryNearStation(userId,lat,lnt);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("beanList", list);
        return FormatUtil.queryListObject(map,"获取附近的站点成功");
    }
}
